<template>
  <div class="app-container">
    <div class="main-container">
      <!-- Sidebar -->
      <aside class="sidebar">
        <div class="sidebar-header">
          <UserIcon class="icon" />
          <span>我的空间</span>
        </div>
        <nav class="sidebar-menu">
          <router-link
              v-for="item in sidebarItems"
              :key="item.id"
              :to="item.route"
              class="sidebar-item"
              :class="{ active: currentItem === item.id }"
              @click="handleSelect(item.id)"
          >
            <component :is="item.icon" class="icon" />
            {{ item.name }}
          </router-link>
        </nav>
      </aside>

      <!-- Main Content -->
      <main class="main-content">
        <router-view></router-view>
      </main>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {
  UserIcon,
  FileTextIcon,
  PlusIcon, FolderIcon
} from 'lucide-vue-next'

const currentItem = ref('1')

const sidebarItems = [
  { id: '3', name: '团队资料夹', icon: FolderIcon, route: '/main/team/folder' },
  { id: '1', name: '空间管理', icon: FileTextIcon, route: '/main/team/management' },
  { id: '2', name: '新增空间', icon: PlusIcon, route: '/main/team/addSpace' },

]

const handleSelect = (id) => {
  currentItem.value = id
}
</script>

<style>
/* CSS Reset and Normalization */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Remove default styles for common elements */
button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* Ensure proper rendering of elements */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.5;
}
</style>

<style scoped>
.app-container {
  min-height: 100vh;
  min-height: 100dvh; /* Modern viewport height */
  background-color: #f5f5f5; /* 修改背景颜色 */
  width: 100%;
  position: relative;
  overflow-x: hidden; /* Prevent horizontal scroll */
}

.main-container {
  display: flex;
  min-height: inherit;
  position: relative;
  width: 100%;
}

.sidebar {
  width: 240px;
  min-width: 240px; /* Prevent shrinking */
  background-color: white;
  border-right: 1px solid #e5e7eb;
  padding: 1.5rem 1rem;
  box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto; /* Enable scroll for overflow content */
  -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  background-color: white;
  z-index: 10;
}

.sidebar-header span {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
}

.sidebar-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  color: #666;
  text-decoration: none;
  border-radius: 0.5rem;
  transition: all 0.2s ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
  user-select: none;
}

.sidebar-item:hover {
  background-color: #f8fafc;
  color: #10b981;
  transform: translateX(4px);
}

.sidebar-item.active {
  background-color: #f0fdf4;
  color: #10b981;
  font-weight: 500;
}

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0; /* Prevent icon from shrinking */
}

.main-content {
  flex: 1;
  padding: 2rem;
  background-color: #ffffff;
  min-width: 0; /* Prevent flex item overflow */
  overflow-x: auto; /* Enable horizontal scroll if needed */
}

/* Dark mode support with proper fallbacks */
@media (prefers-color-scheme: dark) {
  .sidebar {
    background-color: #1a1a1a;
    border-right-color: #333;
  }

  .sidebar-header {
    border-bottom-color: #333;
    background-color: #1a1a1a;
  }

  .sidebar-header span {
    color: #ffffff;
  }

  .sidebar-item {
    color: #999;
  }

  .sidebar-item:hover {
    background-color: #262626;
    color: #10b981;
  }

  .sidebar-item.active {
    background-color: #064e3b;
    color: #10b981;
  }

  .main-content {
    background-color: #1a1a1a;
  }
}

/* Responsive design with proper breakpoints */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    padding: 1rem;
  }
}

/* High-contrast mode support */
@media (forced-colors: active) {
  .sidebar-item.active {
    border: 2px solid CanvasText;
  }
}

/* Print styles */
@media print {
  .sidebar {
    display: none;
  }

  .main-content {
    margin: 0;
    padding: 0;
  }
}
</style>
